package org.dwell.urlfilter.demo.test;

import org.dwell.urlfilter.demo.domain.CoreModule;
import org.dwell.urlfilter.demo.domain.CoreRole;
import org.dwell.urlfilter.demo.domain.CoreUser;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jange on 2016/4/6.
 */
public class CoreModuleDB {

    private static List<CoreModule> moduleList = new ArrayList<CoreModule>();

    //String moduleCode, String moduleName, String moduleUrl, Integer moduleType, String permission

    /**
     *  moduleType:
     *      1. 菜单
     *      2. 页面
     *      3. 按钮
     *      4. 功能
     *
     *
     *
     */
    static {
        moduleList.add(new CoreModule("md00001", "会员管理", "", 1, "menu:member", true));
        moduleList.add(new CoreModule("md00002", "会员管理页面", "/extpay/member/info", 2, "page:member:info", true));
        moduleList.add(new CoreModule("md00003", "新增会员页面", "/extpay/member/create", 2, "page:member:create", true));
        moduleList.add(new CoreModule("md00004", "新增会员按钮", "", 3, "button:member:create", true));
        moduleList.add(new CoreModule("md00005", "新增会员功能", "/extpay/member/add", 4, "fun:member:add", true));

        moduleList.add(new CoreModule("md00006", "没有权限页面", "/error/nopermission", 2, "page:error:nopermission", false));
    }

    public static List<CoreModule> getAll() {
        return moduleList;
    }

    public static CoreModule getByModuleId(String moduleId) {
        for (CoreModule coreModule : moduleList) {
            if(coreModule.getModuleCode().equalsIgnoreCase(moduleId)) {
                return coreModule;
            }
        }

        return null;
    }

    public static List<CoreModule> getByModuleUrl(String shiroUrl) {
        List<CoreModule> modules = new ArrayList<CoreModule>();
        for (CoreModule coreModule : moduleList) {
            if(coreModule.getModuleUrl().equalsIgnoreCase(shiroUrl)) {
                modules.add(coreModule);
            }
        }
        return modules;
    }

    public static List<CoreModule> getNoNeedAuthModules() {
        List<CoreModule> modules = new ArrayList<CoreModule>();
        for (CoreModule coreModule : moduleList) {
            if (!coreModule.isNeedAuth()) {
                modules.add(coreModule);
            }
        }
        return modules;
    }
}
